/*
 * @Description:
 * @Author: 郑灶欣
 * @Date: 2021-11-23 08:45:14
 * @LastEditors: 郑灶欣
 * @LastEditTime: 2021-12-17 14:01:26
 * @FilePath: \vue3-admin\src\store\modules\user.js
 */
import {setToken} from '@/utils/auth.js'
const getDefaultState = () => {
  return {
    userInfo: {},
  };
};
//获取默认信息
const state = getDefaultState();

const mutations = {
  //设置用戶詳情
  SET_USERINFO: (state, userInfo) => {
    state.userInfo = userInfo;
  },
};

const actions = {
  // user login
  login({ commit }, userInfo) {
    return new Promise((resolve, reject) => {
        setToken('---')
        resolve('cc');
    //   login(userInfo)
    //     .then((response) => {
    //       commit("SET_USERINFO", response.data);
    //       resolve(response.data);
    //     })
    //     .catch((error) => {
    //       reject(error);
    //     });
    });
  },
  // 获取用户信息
  getInfo({ commit, state }) {
    return new Promise((resolve, reject) => {
      getInfo(state.token)
        .then((response) => {
          const { data } = response;
          commit("SET_USERINFO", data);
          resolve(data);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
